package ar.edu.unq.wannaplay.utils;

import java.io.Serializable;
import java.util.Calendar;
import java.util.List;

import ar.edu.unq.wannaplay.dtos.EmployeeLicenceDTO;
import ar.edu.unq.wannaplay.services.EmployeeService;

public class CalendarHelper implements Serializable {
    private static final long serialVersionUID = 1L;

    private static CalendarHelper instance;

    private EmployeeService employeeService;

    private List<EmployeeLicenceDTO> data;

    private int month;

    private int year;

    public CalendarHelper() {
        super();
    }

    public CalendarHelper(final EmployeeService service) {
        employeeService = service;
        month = Calendar.getInstance().get(Calendar.MONTH) + 1;
        year = Calendar.getInstance().get(Calendar.YEAR);
        data = this.getEmployeeService().findAllEmployeeLicenceDTO(month, year);
    }

    public static CalendarHelper getInstance(final EmployeeService service) {
        if (instance == null) {
            instance = new CalendarHelper(service);
        }
        instance.updateData();
        return instance;
    }

    private void updateData() {
        this.setData(instance.getEmployeeService().findAllEmployeeLicenceDTO(instance.getMonth(), instance.getYear()));
    }

    public void nextCalendar() {
        if (month == 12) {
            year++;
            month = 1;
        } else {
            month++;
        }
        data = this.getEmployeeService().findAllEmployeeLicenceDTO(month, year);
    }

    public void prevCalendar() {
        if (month == 1) {
            year--;
            month = 12;
        } else {
            month--;
        }
        data = this.getEmployeeService().findAllEmployeeLicenceDTO(month, year);
    }

    // setters&getters
    public void setEmployeeService(final EmployeeService employeeService) {
        this.employeeService = employeeService;
    }

    public EmployeeService getEmployeeService() {
        return employeeService;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(final int month) {
        this.month = month;
    }

    public int getYear() {
        return year;
    }

    public void setYear(final int year) {
        this.year = year;
    }

    public List<EmployeeLicenceDTO> getData() {
        return data;
    }

    public void setData(final List<EmployeeLicenceDTO> data) {
        this.data = data;
    }
}
